﻿using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Mgrs;
using System;
using UnityEngine;

public class PlayerRun : PlayerBaseState {
	public PlayerRun(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => !controller.IsTouchCeiling && !controller.DownInput && !controller.WalkInput);

		AddNewTransition(PlayerStateEnum.Walk, () => controller.WalkInput);
		AddNewTransition(PlayerStateEnum.Slide, () => controller.SlideInput && _controller.DownInput);
		//AddNewTransition(PlayerStateEnum.Crouch, () => controller.DownInput);
	}

	public override void Enter() {
		var handmul = 1;
		if (_controller.StateData.IsCurHandAtk) {
			_controller.PlayAnim(PlayerStateEnum.HandRun);
			handmul = 2;
		}
		else
			_controller.PlayAnim(PlayerStateEnum.SwdRun);
		var mul = _controller.StateData.TimeSpeedMultiple;
		_controller.Velocity = new Vector2(handmul * mul * _controller.ConfigData.RunSpeed * _controller.XInput, _controller.Velocity.y);
		_controller.ChangeDir();
		//Debug.Log($"{_controller.XInput}, {_controller.Velocity}");
		AudioManager.Play(_controller.StateAudio, AudioStr.PlayerRunAudio, true);
	}

	public override void Exit() {
		AudioManager.Stop(_controller.StateAudio);
	}
	bool tmp = true;
	public override void Update() {
		base.Update();
		//Controller.Velocity = new Vector2(Controller.ConfigData.RunSpeed * Controller.XInput, 0);
		//Debug.Log($"{_controller.Velocity.x}");

		//Debug.Log($"{Controller.Velocity}");
	}
}